﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using AspNetCs.Model;
using AspNetCs.IDAL;

namespace AspNetCs.SQLServerDAL
{
    public class Video_DAL:IVideo
    {
        public int Add(VideoModel model)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[10];

            model.AddTime = DateTime.Now;

            paras[0].dbType = SqlDbType.VarChar;
            paras[0].parName = "@Address1";
            paras[0].objValue = model.Address1;

            paras[1].dbType = SqlDbType.VarChar;
            paras[1].parName = "@Address2";
            paras[1].objValue = model.Address2;

            paras[2].dbType = SqlDbType.VarChar;
            paras[2].parName = "@Address3";
            paras[2].objValue = model.Address3;

            paras[3].dbType = SqlDbType.VarChar;
            paras[3].parName = "@Address4";
            paras[3].objValue = model.Address4;

            paras[4].dbType = SqlDbType.VarChar;
            paras[4].parName = "@Address5";
            paras[4].objValue = model.Address5;

            paras[5].dbType = SqlDbType.VarChar;
            paras[5].parName = "@Description";
            paras[5].objValue = model.Description;

            paras[6].dbType = SqlDbType.VarChar;
            paras[6].parName = "@Pic";
            paras[6].objValue = model.Pic;

            paras[7].dbType = SqlDbType.VarChar;
            paras[7].parName = "@Title";
            paras[7].objValue = model.Title;

            paras[8].dbType = SqlDbType.VarChar;
            paras[8].parName = "@VideoType";
            paras[8].objValue = model.VideoType;

            paras[9].dbType = SqlDbType.DateTime;
            paras[9].parName = "@AddTime";
            paras[9].objValue = model.AddTime;

            string cmdText = "insert into video values (@Title,@Pic,@Address1,@Address2,@Address3,@Address4,@Address5,@VideoType,@Description,@AddTime,0,0,0)";
            db dboperate = new db();
            count = dboperate.ExcSql(cmdText, paras);

            return count;
        }

        public int Update(VideoModel model)
        {
            int count = 0;
            db.ParameterArry[] paras=new db.ParameterArry[10];

            

            paras[0].dbType = SqlDbType.VarChar;
            paras[0].parName = "@Address1";
            paras[0].objValue = model.Address1;

            paras[1].dbType = SqlDbType.VarChar;
            paras[1].parName = "@Address2";
            paras[1].objValue = model.Address2;

            paras[2].dbType = SqlDbType.VarChar;
            paras[2].parName = "@Address3";
            paras[2].objValue = model.Address3;

            paras[3].dbType = SqlDbType.VarChar;
            paras[3].parName = "@Address4";
            paras[3].objValue = model.Address4;

            paras[4].dbType = SqlDbType.VarChar;
            paras[4].parName = "@Address5";
            paras[4].objValue = model.Address5;

            paras[5].dbType = SqlDbType.VarChar;
            paras[5].parName = "@Description";
            paras[5].objValue = model.Description;

            paras[6].dbType = SqlDbType.VarChar;
            paras[6].parName = "@Pic";
            paras[6].objValue = model.Pic;

            paras[7].dbType = SqlDbType.VarChar;
            paras[7].parName = "@Title";
            paras[7].objValue = model.Title;

            paras[8].dbType = SqlDbType.VarChar;
            paras[8].parName = "@VideoType";
            paras[8].objValue = model.VideoType;


            paras[9].dbType = SqlDbType.Int;
            paras[9].parName = "@Id";
            paras[9].objValue = model.Id;

            string cmdText = "update video set Address1=@Address1,Address2=@Address2,Address3=@Address3,Address4=@Address4,Address5=@Address5,Description=@Description,Pic=@Pic,Title=@Title,VideoType=@VideoType where id=@Id";
            db dboperate = new db();
            count = dboperate.ExcSql(cmdText,paras);

            return count;
        }

        public DataTable GetDataTable(string filter)
        {
            DataTable dataTable = new DataTable();
            string cmdText = "select *from video where {0}";
            cmdText = string.Format(cmdText,filter);
            db dboperate = new db();
            dataTable = dboperate.GetSql_DataTable(cmdText);
            return dataTable;
        }
    }
}
